<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>谷歌滑块</title>
		<style type="text/css">
			body,
html {
  background: #141414;
  font-family: Roboto Slab
}

.range {
  display: inline-block;
  margin: 36px 20px 20px
}

input[type=range] {
  -webkit-appearance: none;
  position: relative
}

input[type=range]::-webkit-slider-runnable-track {
  width: 300px;
  height: 2px;
  border: none;
  border-radius: 3px
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  border: none;
  height: 12px;
  width: 12px;
  border-radius: 510%;
  background: #141414;
  border: 2px solid #515151;
  margin-top: -5px;
  cursor: pointer
}

.focused::-webkit-slider-thumb {
  box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.15)
}

.clicked::-webkit-slider-thumb {
  -webkit-transform: scale(1.5)
}

.disabled::-webkit-slider-thumb {
  -webkit-transform: scale(0.9);
  box-shadow: 0 0 0 3px #141414;
  background: #515151 !important;
  border-color: #515151 !important
}

input[type=range]:focus {
  outline: none
}

.rangeM input[type=range].disabled::-webkit-slider-runnable-track {
  background: #515151!important
}

.rangeM input[type=range]::-webkit-slider-thumb {
  background: #3f51b5;
  border-color: #3f51b5
}

.range:hover input[type=range]:before {
  color: white;
  content: '50';
  position: absolute;
  font-family: Roboto Slab;
  top: -49px;
  background: #3f51b5;
  padding: 8px 0 3px;
  font-size: 14px;
  width: 30px;
  text-align: center;
  border-radius: 100% 100% 0 0
}

.range:hover input[type=range]:after {
  content: '';
  position: absolute;
  top: -19px;
  left: 50px;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-top: 8px solid #3f51b5;
  font-family: Roboto Slab
}
		</style>
	</head>
	<body>
		<link href='https://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>

<h1 style="text-align:center;color:rgb(150,150,150);font-size:35px;margin:80px 0  50px">Google Material Sliders</h1>
<center>
  <input type="range" max="100" value="0">
  <input type="range" max="100" value="50">
  <input type="range" max="100" value="100">
  <br/>
  <input type="range" max="100" value="0" class="focused">
  <input type="range" max="100" value="50" class="focused">
  <input type="range" max="100" value="100" class="focused">
  <br/>
  <input type="range" max="100" value="0" class="clicked">
  <input type="range" max="100" value="50" class="clicked">
  <input type="range" max="100" value="100" class="clicked">
  <br/>
  <input type="range" max="100" value="0" class="disabled">
  <input type="range" max="100" value="50" class="disabled">
  <input type="range" max="100" value="100" class="disabled">
</center>
<script src="../js/jquery-1.11.2.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	$('input[type=range]').wrap("<div class='range'></div>");
var i = 1;

$('.range').each(function() {
  var n = this.getElementsByTagName('input')[0].value;
  var x = (n / 100) * (this.getElementsByTagName('input')[0].offsetWidth - 8) - 12;
  this.id = 'range' + i;
  if (this.getElementsByTagName('input')[0].value == 0) {
    this.className = "range"
  } else {
    this.className = "range rangeM"
  }
  this.innerHTML += "<style>#" + this.id + " input[type=range]::-webkit-slider-runnable-track {background:linear-gradient(to right, #3f51b5 0%, #3f51b5 " + n + "%, #515151 " + n + "%)} #" + this.id + ":hover input[type=range]:before{content:'" + n + "'!important;left: " + x + "px;} #" + this.id + ":hover input[type=range]:after{left: " + x + "px}</style>";
  i++
});

$('input[type=range]').on("input", function() {
  var a = this.value;
  var p = (a / 100) * (this.offsetWidth - 8) - 12;
  if (a == 0) {
    this.parentNode.className = "range"
  } else {
    this.parentNode.className = "range rangeM"
  }
  this.parentNode.getElementsByTagName('style')[0].innerHTML += "#" + this.parentNode.id + " input[type=range]::-webkit-slider-runnable-track {background:linear-gradient(to right, #3f51b5 0%, #3f51b5 " + a + "%, #515151 " + a + "%)} #" + this.parentNode.id + ":hover input[type=range]:before{content:'" + a + "'!important;left: " + p + "px;} #" + this.parentNode.id + ":hover input[type=range]:after{left: " + p + "px}";
})
</script>
	</body>
</html>
